2020-2021 Sunseeker Telemetry and Lighting System
ref_ex1_ADC12Ctl.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //******************************************************************************
74 //******************************************************************************
75 
76 void main (void)
77 {
78  volatile uint16_t i;
79 
80  //Stop watchdog timer
81  WDT_A_hold(WDT_A_BASE);
82 
83  //Enable A/D channel A0
84  GPIO_setAsPeripheralModuleFunctionInputPin(
85  GPIO_PORT_P6,
86  GPIO_PIN0
87  );
88 
89 
90  //By default, REFMSTR=1 => REFCTL is used to configure the internal reference
91 
92  //If ref generator busy, WAIT
93  while (Ref_isRefGenBusy(REF_BASE)) ;
94  //Select internal ref = 2.5V
95  Ref_setReferenceVoltage(REF_BASE,
96  REF_VREF2_5V);
97  //Internal Reference ON
98  Ref_enableReferenceVoltage(REF_BASE);
99 
100  //Delay (~75us) for Ref to settle
101  __delay_cycles(75);
102 
103  //Initialize the ADC12 Module
104  /*
105  * Base address of ADC12 Module
106  * Use internal ADC12 bit as sample/hold signal to start conversion
107  * USE MODOSC 5MHZ Digital Oscillator as clock source
108  * Use default clock divider of 1
109  */
110  ADC12_A_init(ADC12_A_BASE,
111  ADC12_A_SAMPLEHOLDSOURCE_SC,
112  ADC12_A_CLOCKSOURCE_ADC12OSC,
113  ADC12_A_CLOCKDIVIDER_1);
114 
115  ADC12_A_enable(ADC12_A_BASE);
116 
117  /*
118  * Base address of ADC12 Module
119  * For memory buffers 0-7 sample/hold for 64 clock cycles
120  * For memory buffers 8-15 sample/hold for 4 clock cycles (default)
121  * Disable Multiple Sampling
122  */
123  ADC12_A_setupSamplingTimer(ADC12_A_BASE,
124  ADC12_A_CYCLEHOLD_64_CYCLES,
125  ADC12_A_CYCLEHOLD_4_CYCLES,
126  ADC12_A_MULTIPLESAMPLESENABLE);
127 
128  //Configure Memory Buffer
129  /*
130  * Base address of the ADC12 Module
131  * Configure memory buffer 0
132  * Map input A0 to memory buffer 0
133  * Vref+ = Vref+ (INT)
134  * Vref- = AVss
135  */
136  ADC12_A_configureMemoryParam configureMemoryParam = {0};
137  configureMemoryParam.memoryBufferControlIndex = ADC12_A_MEMORY_0;
138  configureMemoryParam.inputSourceSelect = ADC12_A_INPUT_A0;
139  configureMemoryParam.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_INT;
140  configureMemoryParam.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
141  configureMemoryParam.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
142  ADC12_A_configureMemory(ADC12_A_BASE ,&configureMemoryParam);
143 
144 
145  while (1)
146  {
147  //Enable/Start sampling and conversion
148  /*
149  * Base address of ADC12 Module
150  * Start the conversion into memory buffer 0
151  * Use the single-channel, single-conversion mode
152  */
153  ADC12_A_startConversion(ADC12_A_BASE,
154  ADC12_A_MEMORY_0,
155  ADC12_A_SINGLECHANNEL);
156 
157  //Poll for interrupt on memory buffer 0
158  while (ADC12IFG0 != ADC12_A_getInterruptStatus(ADC12_A_BASE,
159  ADC12IFG0)) ;
160 
161  //SET BREAKPOINT HERE
162  __no_operation();
163  }
164 }
165 
__no_operation()
__delay_cycles(500000)
void main(void)